package br.com.torneio.servicos;

import javax.transaction.SystemException;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import br.com.torneio.entidades.Jogador;

public class Crud {
	private Jogador jogador;

	public void gravaJogador(String nome) throws IllegalStateException,
			SystemException {

		SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();

		Transaction transaction = session.beginTransaction();

		try {
			jogador = new Jogador();
			jogador.setNomeJogador(nome);

			session.save(jogador);
			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
			System.out.println(e.toString());
		}
		session.flush();
		session.close();
	}

}
